package com.itheima.demo05;

public class Num {

    public static void main(String[] args) {

        int[] arr = {11,22,33,44,55,66,77,88,99};

        int i = binarySearch(arr, 22);

        System.out.println(i);
    }


    public static int binarySearch(int[] arr , int a){

        int max = arr.length-1;
        int min = 0;


        while (min<=max) {

            int mid = (max + min) / 2;

            if (arr[mid] == a) {
                return mid;
            } else if (arr[mid] > a) {
                max = mid - 1;
            } else {
                min = mid + 1;
            }
        }

        return -1;
    }
}
